package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-04-26 02:22
 */
public class MinSwapsCouples {
    public int minSwapsCouples(int[] row) {

        int n = row.length;
        UF uf = new UF(n/2);
        for (int i = 0; i < row.length; i+=2) {
            uf.union(row[i]/2,row[i+1]/2);
        }
        return n/2-uf.count();
    }

    public static void main(String[] args) {
        new MinSwapsCouples().minSwapsCouples(new int[]{5,4,2,6,3,1,0,7});
    }
}
